package com.cn.server.handler.mobile;

import com.cn.common.core.exception.ErrorResponse;
import com.cn.common.core.model.Request;
import com.cn.common.core.model.Result;
import com.cn.common.core.model.ResultCode;
import com.cn.common.core.session.Session;
import com.cn.common.core.session.SessionManager;
import com.cn.server.Constant;
import com.cn.server.module.login.ImUser;
import com.cn.server.msg.MessageHandler;

/**
 * 手机端退出
 */
public class LogoutHandler implements MessageHandler {
    @Override
    public Result<?> handle(Request packet, Session session) {
        Object attachment = session.getAttachment();
        if (attachment != null) {
            ImUser imUser = (ImUser) attachment;
            SessionManager.removeSession(imUser.getLoginName());
            return Result.SUCCESS(new ErrorResponse(ResultCode.LOGOUT_CODE,Constant.LOGOUT_SUCCESS));
        } else {
            return Result.ERROR(new ErrorResponse(ResultCode.LOGOUT_CODE, Constant.LOGOUT_FAIL));
        }
    }
}
